package com.example.zhxy.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zhxy.mapper.ClazzMapper;
import com.example.zhxy.pojo.Clazz;
import com.example.zhxy.service.ClazzService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.thymeleaf.util.StringUtils;

@Service
@Transactional
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {
    @Override
    public IPage<Clazz> Ipage(Page<Clazz> page, Clazz clazz) {
        QueryWrapper<Clazz> queryWrapper=new QueryWrapper<>();

        if(!StringUtils.isEmpty(clazz.getGradeName())){
            queryWrapper.eq("grade_name",clazz.getGradeName());
        }if(!StringUtils.isEmpty(clazz.getName())){
            queryWrapper.like("name",clazz.getName());
        }
        queryWrapper.orderByDesc("id");
        Page page1=baseMapper.selectPage(page,queryWrapper);
        return page1;
    }
}
